/*     */ package com.zimbra.cs.index.query;
/*     */ 
/*     */ import com.google.common.base.Strings;
/*     */ import com.zimbra.common.service.ServiceException;
/*     */ import com.zimbra.cs.index.DBQueryOperation;
/*     */ import com.zimbra.cs.index.NoResultsQueryOperation;
/*     */ import com.zimbra.cs.index.QueryOperation;
/*     */ import com.zimbra.cs.mailbox.Mailbox;
/*     */ import com.zimbra.cs.service.util.ItemId;
/*     */ import java.util.ArrayList;
/*     */ import java.util.List;
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ public final class ItemQuery
/*     */   extends Query
/*     */ {
/*     */   private final boolean isAllQuery;
/*     */   private final boolean isNoneQuery;
/*     */   private final List<ItemId> itemIds;
/*     */   
/*     */   public static Query create(Mailbox mbox, String str)
/*     */     throws ServiceException
/*     */   {
/*  43 */     boolean allQuery = false;
/*  44 */     boolean noneQuery = false;
/*  45 */     List<ItemId> itemIds = new ArrayList();
/*     */     
/*  47 */     if (str.equalsIgnoreCase("all")) {
/*  48 */       allQuery = true;
/*  49 */     } else if (str.equalsIgnoreCase("none")) {
/*  50 */       noneQuery = true;
/*     */     } else {
/*  52 */       String[] items = str.split(",");
/*  53 */       for (int i = 0; i < items.length; i++) {
/*  54 */         if (items[i].length() > 0) {
/*  55 */           ItemId iid = new ItemId(items[i], mbox.getAccountId());
/*  56 */           itemIds.add(iid);
/*     */         }
/*     */       }
/*  59 */       if (itemIds.size() == 0) {
/*  60 */         noneQuery = true;
/*     */       }
/*     */     }
/*     */     
/*  64 */     return new ItemQuery(allQuery, noneQuery, itemIds);
/*     */   }
/*     */   
/*     */   ItemQuery(boolean all, boolean none, List<ItemId> ids) {
/*  68 */     this.isAllQuery = all;
/*  69 */     this.isNoneQuery = none;
/*  70 */     this.itemIds = ids;
/*     */   }
/*     */   
/*     */   public boolean hasTextOperation()
/*     */   {
/*  75 */     return false;
/*     */   }
/*     */   
/*     */   public QueryOperation compile(Mailbox mbox, boolean bool)
/*     */   {
/*  80 */     DBQueryOperation dbOp = new DBQueryOperation();
/*  81 */     bool = evalBool(bool);
/*  82 */     if (((!bool) || (!this.isAllQuery)) && ((bool) || (!this.isNoneQuery)))
/*     */     {
/*  84 */       if (((bool) && (this.isNoneQuery)) || ((!bool) && (this.isAllQuery))) {
/*  85 */         return new NoResultsQueryOperation();
/*     */       }
/*  87 */       for (ItemId iid : this.itemIds) {
/*  88 */         dbOp.addItemIdClause(mbox, iid, bool);
/*     */       }
/*     */     }
/*  91 */     return dbOp;
/*     */   }
/*     */   
/*     */   public void dump(StringBuilder out)
/*     */   {
/*  96 */     out.append("ITEMID");
/*  97 */     if (this.isAllQuery) {
/*  98 */       out.append(",all");
/*  99 */     } else if (this.isNoneQuery) {
/* 100 */       out.append(",none");
/*     */     } else {
/* 102 */       for (ItemId id : this.itemIds) {
/* 103 */         out.append(',');
/* 104 */         out.append(id.toString());
/*     */       }
/*     */     }
/*     */   }
/*     */   
/*     */   public void sanitizedDump(StringBuilder out)
/*     */   {
/* 111 */     out.append("ITEMID");
/* 112 */     if (this.isAllQuery) {
/* 113 */       out.append(",all");
/* 114 */     } else if (this.isNoneQuery) {
/* 115 */       out.append(",none");
/*     */     } else {
/* 117 */       out.append(Strings.repeat(",$TEXT", this.itemIds.size()));
/*     */     }
/*     */   }
/*     */ }


/* Location:              /home/mint/zimbrastore.jar!/com/zimbra/cs/index/query/ItemQuery.class
 * Java compiler version: 7 (51.0)
 * JD-Core Version:       0.7.1
 */